/**
 * GTHttpParameter.m
 *
 * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy of the License 
 * at http://www.mozilla.org/MPL/
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
 * either express or implied. See the License for the specific language governing rights and limitations 
 * under the License.
 *
 * The Original Code is gcast-toolbox4iphone.
 *
 * The Initial Developers of the Original Code is Giannandrea Castaldi.
 */
#import "GTHttpParameter.h"

@interface GTHttpParameter ()
@property(nonatomic,retain,readwrite) NSString *name;
@property(nonatomic,retain,readwrite) NSString *value;
@end

@implementation GTHttpParameter
@synthesize name, value;

+ (id)parameterWithName:(NSString*)aName value:(NSString*)aValue {
  return [[[self alloc] initWithName:aName value:aValue] autorelease];
}

- (id)initWithName:(NSString*)aName value:(NSString*)aValue {
  if ((self = [super init])) {
    self.name = aName;
    self.value = aValue;
  }
  return self;
}

- (void)dealloc {
  [name release];
  [value release];
  [super dealloc];
}

- (id)initWithCoder:(NSCoder *)aDecoder {
  return [self initWithName:[aDecoder decodeObjectForKey:@"name"] value:[aDecoder decodeObjectForKey:@"value"]];
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
  [aCoder encodeObject:self.name forKey:@"name"];
  [aCoder encodeObject:self.value forKey:@"value"];
}

- (id)copyWithZone:(NSZone *)zone {
  return [[GTHttpParameter allocWithZone:zone] initWithName:self.name value:self.value];
}

- (BOOL)isEqual:(id)object {
  BOOL result = FALSE;
  if (object == self) {
    result = TRUE;
  }
  else if (object != nil && [object isKindOfClass:[self class]]) {
    GTHttpParameter *anotherObject = object;
    result = ((self.name == anotherObject.name || [self.name isEqualToString:anotherObject.name])
              && ((self.value == anotherObject.value) || [self.value isEqualToString:anotherObject.value]));
  }
  return result;
}

- (NSUInteger)hash {
  return [self.name hash] + [self.value hash];
}

- (NSString*)description {
  return [NSString stringWithFormat:@"[GTHttpParameter: name=%@, value=%@]", self.name, self.value];
}



@end
